<template>
  <div class="box">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>商家入驻</span>
        </div>
      </template>
      <el-form ref="registerForm" style="max-width: 600px" :model="business" :rules="rules" label-width="auto"
        status-icon>
        <el-form-item label="商家账号" prop="account">
          <el-input v-model="business.account" />
        </el-form-item>

        <el-form-item label="商家密码" prop="password">
          <el-input v-model="business.password" />
        </el-form-item>

        <el-form-item label="商家电话" prop="telephone">
          <el-input v-model="business.telephone" />
        </el-form-item>

        <el-form-item label="商家联系人" prop="contact">
          <el-input v-model="business.contact" />
        </el-form-item>

      </el-form>
      <template #footer>
        <el-space spacer="|">
          <el-button type="primary" @click="registerBusiness">注册</el-button>
          <el-button type="primary" @click="resetBusiness">重置</el-button>
          <el-link @click="$router.push('/login')">跳转到登录页面</el-link>
        </el-space>

      </template>
    </el-card>
  </div>
</template>

<script>
import {businessRegister} from '@/api/business.js'
import qs from 'qs'
import { ElMessage } from 'element-plus'
export default {
  data() {

    return {
      business: {},
      rules: {
        account: { required: true, message: '账号不能为空', trigger: 'blur' },
        password: [
          { required: true, message: '账号不能为空', trigger: 'blur' },
          { min: 6, max: 10, message: '密码位数在6到10之间', trigger: 'blur' }],
        telephone: { required: true, message: '电话号不能为空', trigger: 'blur' },
        contact: { required: true, message: '联系人不能为空', trigger: 'blur' }
      }
    }
  },
  methods: {
    registerBusiness() {
      this.$refs.registerForm.validate((valid) => {
        if (valid) {
          // 发起异步请求,实现注册功能
          businessRegister(this.business)
            .then((response)=> {
              if(response.data == 1){
                this.$router.push('/login')
              }else{
                ElMessage.error('注册失败！')
              }
            });
        }
      })
    },
    resetBusiness() {
      this.$refs.registerForm.resetFields();
    }
  }
}
</script>

<style scoped>
.box {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  /* background-image: url(https://ppui-static-pc.cdn.bcebos.com/static/passpc-account/img/reg_bg_min.jpg); */
}

.el-card {
  width: 500px;
  height: 380px;
}
</style>